import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:package_info_plus/package_info_plus.dart';

class AppUtils {
  static late PackageInfo packageInfo;

  static bool get isAndroid => !isWeb && Platform.isAndroid;

  static bool get isIOS => !isWeb && Platform.isIOS;

  static bool get isLinux => !isWeb && Platform.isLinux;

  static bool get isWindows => !isWeb && Platform.isWindows;

  static bool get isMacOS => !isWeb && Platform.isMacOS;

  static bool get isWeb => kIsWeb;

  static Future<void> init() async {
    await _initDeviceInfo();
  }

  ///初始化信息
  static Future<void> _initDeviceInfo() async {
    if (!isWeb) {
      WidgetsFlutterBinding.ensureInitialized();
    }
    packageInfo = await PackageInfo.fromPlatform();
  }

  static String get platform {
    return Platform.isAndroid ? 'Android' : (Platform.isIOS ? 'iOS' : '');
  }

  //APP名称
  static String get appName => packageInfo.appName;

  //包名
  static String get packageName => packageInfo.packageName;

  //版本名
  static String get version => packageInfo.version;

  //版本号
  static String get buildNumber => packageInfo.buildNumber;

  static bool get isBeta => isDebug || version.contains("beta");

  static bool get isDebug => kDebugMode;
}
